#include "StdAfx.h"
#include "Utils.h"


CUtils::CUtils(void)
{
}


CUtils::~CUtils(void)
{
}

VOID CUtils::GetFileNameFromPath(CString& strPath, CString& strName)
{
	CString strFilename = strPath;

	INT nLastPosOfQuestionMark = -1;
	nLastPosOfQuestionMark = strFilename.ReverseFind(_T('?')); // This might be an URL
	if(nLastPosOfQuestionMark > -1)
	{
		strFilename = strFilename.Mid(0, nLastPosOfQuestionMark);
	}
	INT nLastPosOfSlash = strFilename.ReverseFind(_T('/'));
	if(nLastPosOfSlash > -1)
	{
		strFilename = strFilename.Mid(nLastPosOfSlash + 1);
	}
	INT nLastPosOfBackslash = strFilename.ReverseFind(_T('\\'));
	if(nLastPosOfBackslash > -1)
	{
		strFilename = strFilename.Mid(nLastPosOfBackslash + 1);
	}
	strName = strFilename;
}

VOID CUtils::GetFileExt(CString& strPath, CString& strFileExt)
{
	CString strFilename = strPath;

	INT nLastPosOfQuestionMark = -1;
	nLastPosOfQuestionMark = strFilename.ReverseFind(_T('?')); // This might be an URL
	if(nLastPosOfQuestionMark > -1)
	{
		strFilename = strFilename.Mid(0, nLastPosOfQuestionMark);
	}
	INT nLastPosOfSlash = strFilename.ReverseFind(_T('/'));
	if(nLastPosOfSlash > -1)
	{
		strFilename = strFilename.Mid(nLastPosOfSlash + 1);
	}
	INT nLastPosOfBackslash = strFilename.ReverseFind(_T('\\'));
	if(nLastPosOfBackslash > -1)
	{
		strFilename = strFilename.Mid(nLastPosOfBackslash + 1);
	}

	INT nLastPosOfDot = strFilename.ReverseFind(_T('.'));
	strFileExt = strFilename.Right(strFilename.GetLength() - nLastPosOfDot - 1);
}